<?php
/**
 * Created by PhpStorm.
 * User: a4041
 * Date: 2018/6/13
 * Time: 13:46
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laravel\Scout\Searchable;

class Shop extends Model
{
//    use Searchable;
    //软删除
    use SoftDeletes;
    protected $guarded = ['id', 'created_at', 'updated_at'];
    //保护字段
    protected $hidden = ['id_pic','id_pic_back'];
    /**
     * 获取关联到商家详细信息
     */
    public function shopinfo()
    {
        return $this->hasOne('App\Models\ShopInfo','shop_id','id');
    }

    /**
     * 获取关联到商家店员信息
     */
    public function shopclecks()
    {
        return $this->hasMany('App\Models\ShopClerk','shop_id','id');
    }

    /**
     * 获取关联到用户表详细信息
     */
    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }

    /**
     * 获取关联到商家菜单信息
     */
    public function shopdishes()
    {
        return $this->hasMany('App\Models\ShopDish','shop_id','id');
    }

    /**
     * 获取关联到商家菜单信息
     */
    public function shoproomtable()
    {
        return $this->hasMany('App\Models\ShopRoomTable','shop_id','id');
    }
    public function shopmenu()
    {
        return $this->hasMany('App\Models\ShopMenu','shop_id','id');
    }
    /**
     * 获取关联到商家评论信息
     */
    public function shopcomment()
    {
        return $this->hasMany('App\Models\Comment','shop_id','id');
    }
    /**
     * 获取关联到商家优惠券信息
     */
    public function shopcoupon()
    {
        return $this->hasMany('App\Models\Coupon','shop_id','id');
    }
//    public function searchableAs()
//    {
//        return 'shop';
//    }
//
//    public function toSearchableArray()
//    {
//        return [
//          'shop_name'=>$this->shop_name,
//          'shop_address' => $this->shop_address,
//          'is_check'=> $this->is_check,
//        ];
//    }

    public function getIt($id){
        return $this->where('id',$id)->get();
    }

    /**
     *      判断该商家是否是属于这个用户的
     * @param $shop_id  商家ID
     * @param $user_id  用户ID
     * @return bool
     */
    public static function checkIsShop($shop_id,$user_id){
        $count = self::where('id',$shop_id)->where('user_id',$user_id)->count();
        if ($count){
            return true;
        }else{
            return false;
        }
    }
    /**
     * 获取单单立减
     * @param $user_id  用户ID
     * @return bool
     */
    public function shopcheapen(){
        return $this->hasOne('App\Models\ShopCheapen','shop_id','id');
    }
}